﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using System.ComponentModel;
using System.Collections.Generic;
namespace WPFExcelReport
{
    public partial class TSAE04
    {
        public TSAE04()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VMEKOPF();
            DataContext = MV;
            InitializeComponent();
        }

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
        }
        public override void OnEXAUFChg(string vlaue)
        {
            TBMain.Clear();
            if (EXAUF.Length < 8)
                return;

            dwData = TMV.TBMain.NewRow();

            dwData["MEKMANDANT"] = app.Mandant;
            dwData["MEKAGANG"] = " AND MEKAGANG='" + AGANG + "'";
            dwData["MEKMTYP"] = " AND MEKMTYP='" + EXAUF.Substring(0, 8) + "'";
            dwData["MEKMNRKRS"] = " AND MEKMNRKRS='" + KST.Substring(0, 2) + "'";
            dwData["MEKMLFDNR"] = " AND MEKMLFDNR='" + KST.Substring(2, 4) + "'";
            //KEY = TMV.APAKANRKRS 2 + TMV.APAKALFDNR 6 + TMV.APAKAFOLGE 3 + TMV.APAKAEVOR  4+ TMV.APAKPKSTKRS  2+ TMV.APAKPKST 4 + TMV.APAKMTYP 8 + TMV.APAKAGANG + TMV.APAKEVARHNR + TMV.APAKEVARUNR;
            SResult = TMV.QMAE02(dwData);
            foreach(DataRow row in SResult.Tables[0].Rows)
            {
                row["DES"] = Helpers.Helper.GetGB2312Value(row["DES"].ToString()).Trim();
            }
            MergeData(SResult, false);
            base.OnEXAUFChg(vlaue);
        }  
        public override void ComboBox_DropDownOpened(object sender, EventArgs e)
        {
            OnEXAUFChg(EXAUF);
            base.ComboBox_DropDownOpened(sender, e);
        }
        public override void LOADALL()
        {
            vwMaster.View.MoveCurrentTo(-1);
            base.LOADALL();
        }
        public override void ManageCommand(object sender, RoutedEventArgs e)
        {
            if (IsManage)
            {
                OnEXAUFChg(EXAUF);
            }
            base.ManageCommand(sender, e);
        }
    }

}
